package com.zygh.lz.dao.role;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zygh.lz.entity.role.SysRole;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


public interface SysRoleMapper extends BaseMapper<SysRole> {
    @Select("select * from sys_role sr where sr.section_id = #{sectionId}")
    List<SysRole> getRole(Integer sectionId);

    @Select("<script>" +
            " select * from staff sf " +
            " left join sys_user_role sur on sf.sys_staff_id =  sur.user_id" +
            " left join sys_role sr on  sur.role_id = sr.id " +
            " <where> " +
            " sr.section_id is not null " +
            "<if test='sysSectionId != null'>" +
            " and sf.sys_section_id = #{sysSectionId} " +
            "</if>" +
            " <if test='id != null'>" +
            " and exists (select 1 from sys_user_role sur where sur.role_id=#{id} and sf.sys_staff_id = sur.user_id )  " +
            "</if>" +
            "</where>" +
            "</script>  ")
    List<Map> selectRole(@Param("sysSectionId") Integer sysSectionId, @Param("id") Integer id);
}
